import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class Exercise {
    public static void main(String[] args) throws DocumentException {
        //1. 得到 解析器
        SAXReader reader = new SAXReader();
        Document document = reader.read(new File("src/Main/Java/Exercise.xml"));
        List<Element> books = document.getRootElement().elements("book");
        for (Element book : books) {
            Element name = book.element("name");
            Element author = book.element("author");
            Element price = book.element("price");
            String id = book.attributeValue("id");
            Book book1 = new Book();
            book1.setID(Integer.parseInt(id));
            book1.setName(name.getText());
            book1.setPrice(Double.parseDouble(price.getText()));
            book1.setAuthor(author.getText());
            System.out.println("book1 对象信息 = " + book1);
        }
    }
}
